package com.yunfeisoft.business.service.impl;

import com.applet.base.BaseServiceImpl;
import com.applet.sql.separation.DataSourceChange;
import com.applet.utils.Page;
import com.yunfeisoft.business.dao.inter.PmsSkuStockDao;
import com.yunfeisoft.business.model.PmsSkuStock;
import com.yunfeisoft.business.service.inter.PmsSkuStockService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * ClassName: PmsSkuStockServiceImpl
 * Description: 商品SKU表(商品库存量单位表)service实现
 * Author: Jackie liu
 * Date: 2020-06-02
 */
@Service("pmsSkuStockService")
public class PmsSkuStockServiceImpl extends BaseServiceImpl<PmsSkuStock, String, PmsSkuStockDao> implements PmsSkuStockService {

    @Override
    @DataSourceChange(slave = true)
    public Page<PmsSkuStock> queryPage(Map<String, Object> params) {
        return getDao().queryPage(params);
    }

    @Override
    public List<PmsSkuStock> queryByProductId(String productId) {
        return getDao().queryByProductId(productId);
    }

    @Override
    public int modify(List<PmsSkuStock> skuStockList, String productId) {
        getDao().deleteByProductId(productId);
        if (CollectionUtils.isNotEmpty(skuStockList)) {
            getDao().batchInsert(skuStockList);
        }
        return 1;
    }
}